package com.zhr.tea.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhr.tea.R;
import com.zhr.tea.entity.ZiShaBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 * Created by 毛懿 on 2016/11/5 11:20.
 * 邮箱：1334964028@qq.com
 */

public class ZiShaAdapter extends RecyclerView.Adapter {
    public static final int TYPE_HEAD = -1;
    public static final int TYPE_HUXING = -2;
    public static final int TYPE_JIANGREN = -3;

    private Context context;
    private List<ZiShaBean.ContentBean.PotListBean> pot;
    private List<ZiShaBean.ContentBean.CraftsmanListBean> craftsman;

    public ZiShaAdapter(Context context, List<ZiShaBean.ContentBean.CraftsmanListBean> craftsman, List<ZiShaBean.ContentBean.PotListBean> pot) {
        this.context = context;
        this.craftsman = craftsman;
        this.pot = pot;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return TYPE_HEAD;
        } else if (position <= pot.size()) {
            return TYPE_HUXING;
        } else {
            return TYPE_JIANGREN;
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_HEAD:
                return new TextViewHolder(LayoutInflater.from(context).inflate(R.layout.item_zisha_head, parent, false));
            case TYPE_HUXING:
                return new HuXingViewHolder(LayoutInflater.from(context).inflate(R.layout.item_huxing, parent, false));
            case TYPE_JIANGREN:
                return new JiangRenViewHolder(LayoutInflater.from(context).inflate(R.layout.item_jiangren, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position > 0 && position <= craftsman.size()) {
            HuXingViewHolder holder1 = (HuXingViewHolder) holder;
            Glide.with(context).load(pot.get(position - 1).getPotTypeImg()).into(holder1.ivHuxing);
            holder1.tvHuxing.setText("-" + pot.get(position - 1).getPotTypeName() + "-");
        } else {
            JiangRenViewHolder holder2 = (JiangRenViewHolder) holder;
            Glide.with(context).load(craftsman.get(position - pot.size() - 1).getCraftsmanHeadUrl()).into(holder2.ivJiangren);
            holder2.tvJiangrenName.setText(craftsman.get(position - pot.size() - 1).getCraftsmanName());
            holder2.tvJiangrenTitle.setText(craftsman.get(position - pot.size() - 1).getLevel());
            holder2.tvJiangrenPingfen.setText("评分：暂无");
            holder2.tvJiangrenPrice.setText("价位：" + craftsman.get(position - pot.size() - 1).getLowestPrice());
            if (position == pot.size() + 1) {
                holder2.tvJiangrenHead.setVisibility(View.VISIBLE);
            } else {
                holder2.tvJiangrenHead.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public int getItemCount() {
        return craftsman.size() + pot.size() + 1;
    }

    public class TextViewHolder extends RecyclerView.ViewHolder {

        public TextViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class HuXingViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_huxing)
        ImageView ivHuxing;
        @BindView(R.id.tv_huxing)
        TextView tvHuxing;

        public HuXingViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public class JiangRenViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_jiangren_head)
        TextView tvJiangrenHead;
        @BindView(R.id.iv_jiangren)
        ImageView ivJiangren;
        @BindView(R.id.tv_jiangren_name)
        TextView tvJiangrenName;
        @BindView(R.id.tv_jiangren_title)
        TextView tvJiangrenTitle;
        @BindView(R.id.tv_jiangren_pingfen)
        TextView tvJiangrenPingfen;
        @BindView(R.id.tv_jiangren_price)
        TextView tvJiangrenPrice;
        @BindView(R.id.tv_jiangren_dingzhi)
        TextView tvJiangrenDingzhi;

        public JiangRenViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
